<template>
	<view class="box-wp" v-if="list.length>0">
		<view class="item" v-for="(info,index) in list" :key="index" @click="toInfo(info)">
			<view class="main">
				<view class="left">
					<u--image :src="info.image" width="340rpx" height="160rpx" mode="aspectFill"></u--image>
					<view class="left-price-box">
						<view class="left-price">
							{{info.price}}

						</view>
						<view class="left-unit">
							元
						</view>
					</view>

					<view class="left-name">
						{{info.name}}代金券
					</view>

				</view>
				<view class="right">
					<view class="title u-line-1">
						{{info.name}}
					</view>
					<view class="cont-price">
						<view class="price">
							<text style="font-size:34rpx ;">￥</text>
							<text style="font-size:34rpx ;"> {{info.price}}</text>
						</view>
					</view>
					<view class="option-btn-wp">
						<view class="option-btn" @click.stop="goToShareCoupon(info)">
							赠送
						</view>
						<view class="option-btn" @click.stop="delMyCoupon(info)">
							作废
						</view>

					</view>
				</view>
			</view>

		</view>
	</view>
	<u-empty marginTop="50" mode="list" textSize="30" iconSize="70" v-else>
	</u-empty>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				pageNo: 1,
				total: 0,
				pageSize: 10,

			}
		},
		// created() {
		// 	this.getList(1)
		// },
		methods: {
			async getList(arg) {
				uni.showLoading({})
				if (arg == 1) {
					this.pageNo = 1
					this.list = []
					this.total = 0
				}
				let {
					openid
				} = uni.getStorageSync('openId')
				let res = await this.$api.getMsVoucherPage({
					openId: openid,
					pageNo: this.pageNo,
					pageSize: this.pageSize,
					status: 0
				})
				if (res.success) {

					console.log(res.result.records);
					this.list = [...this.list, ...res.result.records]
					this.total = res.result.total
				} else {
					this.list = []
					this.total = 0
				}
				uni.hideLoading()
			},
			goToShareCoupon(item) {
				console.log(item);
				uni.navigateTo({
					url: `/pagesMall/coupon/myCouponDetail?id=${item.id}`
				})
			},
			toInfo(item) {
				console.log(item)
				uni.navigateTo({
					url: `/pagesMall/coupon/myCouponDetail?id=${item.id}`
				})
			},
			reachBottom() {
				if (this.pageNo * this.pageSize > this.total) {
					uni.showToast({
						title: '没有更多数据',
						icon: 'none'
					})
				} else {
					this.pageNo++
					this.getList()
				}
			},
			delMyCoupon({
				id
			}) {
				let that = this
				uni.showModal({
					title: '提示',
					content: '是否删除该代金券',
					success: async (modal) => {
						if (modal.confirm) {
							let res = await that.$api.delteMyCoupon(
								id
							)
							if (res.success) {
								that.getList(1)
							} else {
								uni.showToast({
									title: res.message,
									icon: 'none'
								})
							}
						}
					}
				});

			},
		}
	}
</script>

<style lang="scss" scoped>
	.box-wp {

		background-color: #f7f8fa;
		height: 100%;

		.item {
			border-radius: 16rpx;
			background-color: #fff;
			margin: 32rpx;
			padding: 20rpx;

			.main {
				display: flex;
				justify-content: space-between;

				.left {
					margin-top: 5rpx;
					margin-right: 32rpx;
					position: relative;

					.left-name {
						position: absolute;
						font-size: 24rpx;
						font-family: Source Han Sans CN, Source Han Sans CN;
						font-weight: 500;
						line-height: 34rpx;
						background: linear-gradient(180deg, #F9D3A8 0%, #FEF7E8 46%, #F9D3A8 100%);
						-webkit-background-clip: text;
						-webkit-text-fill-color: transparent;
						top: 100rpx;
						left: 24rpx;
					}

					.left-price-box {
						display: flex;
						align-items: flex-end;
						position: absolute;
						top: 22rpx;
						left: 24rpx;

						.left-price {

							font-size: 80rpx;
							font-family: Source Han Sans CN, Source Han Sans CN;
							font-weight: bold;
							line-height: 80rpx;
							background: linear-gradient(180deg, #F9D3A8 0%, #FEF7E8 46%, #F9D3A8 100%);
							-webkit-background-clip: text;
							-webkit-text-fill-color: transparent;

						}

						.left-unit {
							width: 24rpx;
							height: 24rpx;
							background: linear-gradient(180deg, #F9D3A8 0%, #FEF7E8 46%, #F9D3A8 100%);
							font-size: 16rpx;
							font-family: Source Han Sans CN, Source Han Sans CN;
							font-weight: 400;
							color: #922126;
							line-height: 24rpx;
							border-radius: 50%;
							text-align: center;
							position: relative;
							top: -2rpx;
						}

					}


					image {
						border-radius: 5rpx;
						width: 140rpx;
						height: 140rpx;
					}
				}

				.right {
					flex: 1;

					.title {
						overflow: hidden;
						width: 450rpx;
						height: 40rpx;
						font-size: 28rpx;
						font-weight: 600;
						color: #1D2129;
					}

					.cont-price {

						height: 70rpx;
						display: flex;
						align-items: center;

						.count {
							height: 40rpx;
							font-size: 28rpx;
							font-weight: 400;
							color: #86909C;
							line-height: 39rpx;
						}

						.goods-tag {
							border-radius: 6rpx;
							border: 1rpx solid #FF7D00;
							padding: 4rpx 10rpx;
							margin-left: 20rpx;
							text-align: center;
							width: 100rpx;
							height: 28rpx;
							font-size: 20rpx;
							font-weight: 400;
							color: #FF7D00;
							line-height: 28rpx;

						}

						.price {
							color: #FF3131;
						}
					}

					.option-btn-wp {
						display: flex;


						.option-btn {
							text-align: center;
							width: 112rpx;
							height: 48rpx;
							border-radius: 200rpx 200rpx 200rpx 200rpx;
							opacity: 1;
							border: 2rpx solid #86909C;
							font-size: 24rpx;
							font-weight: 400;
							color: #86909C;
							line-height: 48rpx;
							margin-left: 20rpx;

						}


					}




				}
			}

			.bottom {
				.sell-box {
					margin-top: 24rpx;

					.sell-box-name {
						height: 40rpx;
						font-size: 28rpx;
						font-weight: 400;
						color: #4E5969;
						line-height: 39rpx;
					}

					.sell-box-name2 {
						height: 40rpx;
						font-size: 28rpx;
						font-weight: 600;
						color: #1D2129;
						line-height: 39rpx;
					}
				}

				.time-box {
					margin-top: 24rpx;

					.time {
						height: 40rpx;
						font-size: 28rpx;
						font-weight: 400;
						color: #86909C;
						line-height: 39rpx;
					}

					.detail {
						height: 40rpx;
						font-size: 28rpx;
						font-weight: 400;
						color: #276AEE;
						line-height: 39rpx;
					}
				}

			}




		}

	}
</style>